<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs2" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    /*
     *@Description: 招标立项带出到采购决策综合评审意见明细
     *@Param: [request, response]
     *@return: void
     *@Author: Dusongsong
     *@Date: 2021/1/13
     */
    String cglx = Util.null2String( request.getParameter( "cglx" ) );
    String lc = Util.null2String( request.getParameter( "lc" ) );
    List<Map<String, String>> mapList1 = new ArrayList<>();
    List<Map<String, String>> mapList2 = new ArrayList<>();
    String gystb_table = bb.getPropValue( "srm_wf_table", "gystb_table" );
    String zblx_table = bb.getPropValue( "srm_wf_table", "zblx_table" );
    JSONObject jsonData = new JSONObject();
    //明细表2
    String sql = "select gcxm from " + zblx_table + " where id=? and lc=?";
    rs.executeQuery( sql, cglx, lc );
    bb.writeLog( sql, String.join( ",",cglx, lc ));
    if (rs.next()) {
        Map<String, String> dataMap2 = new HashMap<>();
        String gcxm = Util.null2String( rs.getString( "gcxm" ) );
        Map<String,String> resutlMap = getGcxmName(gcxm);
        dataMap2.put( "gcxm", gcxm);
        dataMap2.put( "gcxmname", resutlMap.get( "project_name2" ) );
        dataMap2.put( "xmbh", resutlMap.get("project_code") );
        mapList2.add( dataMap2 );
    }
     //明细表1
    String sql1 = "select gysmc,zhdf,row_number() over( order by zhdf desc) as pm from v_srm_lgj_zh where xmmc=? and lc=? order by zhdf desc";
    rs.executeQuery( sql1, cglx, lc );
    bb.writeLog( sql1, String.join( ",", cglx, lc ) );
    while (rs.next()) {
        Map<String, String> dataMap = new HashMap<>();
        String gysmc = Util.null2String( rs.getString( "gysmc" ) );
        String gysmcname = getGysmcName( gysmc );
        String pm = Util.null2String( rs.getString( "pm" ) );
        String zhdf = Util.null2String( rs.getString( "zhdf" ) );

        String sql2 = "select id,zje from " + gystb_table + " where xmmc=? and gysmc=? and lc=? and requestid is not null";
        rs1.executeQuery( sql2, cglx,gysmc, lc );
        rs1.writeLog( sql2, String.join( "," ,cglx,gysmc, lc) );
        rs1.next();
        String zje = Util.null2String( rs1.getString( "zje" ) );
        String mainid = Util.null2String( rs1.getString( "id" ) );

        String sql3 = "select fkfs,fkbl from " + gystb_table + "_dt7 where mainid='" + mainid + "'";
        rs2.executeQuery(sql3);
        String strs = "";
        while (rs2.next()) {
            String fkfs = Util.null2String( rs2.getString( "fkfs" ) );
            String fkbl = Util.null2String( rs2.getString( "fkbl" ) );
            String str = fkfs + "-" + fkbl + "%";
            strs = "".equals( strs ) ? str : "," + str;
        }

        rs2.executeQuery( "select fktj,xz from " + gystb_table + "_dt8 where mainid='" + mainid + "'" );
        String fktj = "";
        while (rs2.next()) {
            String xz = Util.null2String( rs2.getString( "xz" ) );
            if ("1".equals( xz )) {
                fktj = Util.null2String( rs2.getString( "fktj" ) );
            }
        }

        String fktjs = strs +";"+ fktj;
        dataMap.put( "pm", pm );
        dataMap.put( "fktj", fktjs );
        dataMap.put( "gysmc", gysmc );
        dataMap.put( "gysmcname", gysmcname );
        dataMap.put( "zje", zje );
        dataMap.put( "zhdf", zhdf );
        dataMap.put( "pm", pm );
        mapList1.add( dataMap );
    }

    jsonData.put( "dataList1", mapList1 );
    jsonData.put( "dataList2", mapList2 );
    out.print( jsonData.toJSONString() );
    bb.writeLog( "getZhpsyj_Ajax=" + jsonData.toJSONString() );
%>
<%!
    public static String getGysmcName(String id) {
        RecordSet rs = new RecordSet();
        String gysmc = "";
        rs.executeQuery( "select gysmc from uf_srm_gyskpx where id='" + id + "'" );
        rs.next();
        gysmc = Util.null2String( rs.getString( "gysmc" ) );
        return gysmc;
    }
    public static Map<String,String> getGcxmName(String id){
        Map<String,String> map = new HashMap<>(  );
        RecordSet rs = new RecordSet();
        String project_name2 = "";
        String project_code = "";
        rs.executeQuery( "select project_name2,project_code from uf_CRM_ENG_CON_INFO where id='" + id + "'" );
        if(rs.next()){
            project_name2 = Util.null2String( rs.getString( "project_name2" ) );
            project_code = Util.null2String( rs.getString( "project_code" ) );
        }
        map.put("project_name2",project_name2);
        map.put("project_code",project_code);
        return map;
    }
%>

